---
category: Validator
created: '2020-04-19'
title: Check if a string contains whitespace
updated: '2021-10-13'
---

**JavaScript version**

```js containsWhitespace.js
const containsWhitespace = (str) => (str) => /\s/.test(str);
```

**TypeScript version**

```ts containsWhitespace.ts
const containsWhitespace =
    (str: string): boolean =>
    (str) =>
        /\s/.test(str);
```

**Examples**

```js examples.js
containsWhitespace('hello world'); // true
```
